package com.wanjia.seal.manager.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wanjia.seal.manager.annotation.LoginToken;
import com.wanjia.seal.manager.controller.ex.BankexistException;
import com.wanjia.seal.manager.controller.ex.DataNotFoundException;
import com.wanjia.seal.manager.entity.BankInfoTB;
import com.wanjia.seal.manager.entity.SysMenu;
import com.wanjia.seal.manager.entity.SysUserRole;
import com.wanjia.seal.manager.mapper.BankInfoTBMapper;
import com.wanjia.seal.manager.mapper.CodeTBMapper;
import com.wanjia.seal.manager.mapper.SysUserRoleMapper;
import com.wanjia.seal.manager.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/api")
@Api(tags = "人员角色")
@Slf4j
public class SysUserRoleController extends BaseController{

    @Autowired
    SysUserRoleMapper sysUserRoleMapper;


    @ResponseBody
    @GetMapping("/alluserrole")
    @ApiOperation(value = "查询所有人员角色关系表", notes = "查询是否成功")
    @LoginToken
    public JsonResult<List<SysUserRole>> getAll() {
        List<SysUserRole> sysUserRoles = sysUserRoleMapper.selectList(null);
        return new JsonResult<>(OK,sysUserRoles);
    }

    @ResponseBody
    @GetMapping("/userrole")
    @ApiOperation(value = "用ID查询人员角色关系表", notes = "查询是否成功")
    @LoginToken
    public JsonResult<SysUserRole> getById(Integer UserId){
        SysUserRole sysUserRole = sysUserRoleMapper.selectById(UserId);
        return new JsonResult<>(OK,sysUserRole);
    }
    @ResponseBody
    @PutMapping("/updateuserrole")
    @ApiOperation(value = "更新人员角色关系表", notes = "更新人员角色关系表是否成功")
    @LoginToken
    public JsonResult upData(@RequestBody SysUserRole sysUserRole){
        sysUserRoleMapper.updateById(sysUserRole);
        return new JsonResult(OK);
    }

    @ResponseBody
    @PostMapping("/adduserrole")
    @ApiOperation(value = "添加人员角色关系表", notes = "添加人员角色关系表是否成功")
    @LoginToken
    public JsonResult addRole(@RequestBody SysUserRole sysUserRole){
        sysUserRoleMapper.insert(sysUserRole);
        return new JsonResult(OK);
    }
    @ResponseBody
    @DeleteMapping("/deleteuserrole")
    @ApiOperation(value = "删除人员角色关系表", notes = "删除人员角色关系表是否成功")
    @LoginToken
    public JsonResult update(Integer UserId) {
        sysUserRoleMapper.deleteById(UserId);
        return new JsonResult(OK);
    }

}
